const {
  override,
  fixBabelImports,
  addWebpackAlias,
  addLessLoader,
  overrideDevServer,
  addWebpackModuleRule,
} = require("customize-cra");

const devServerConfig = (config) => {
  return {
    ...config,
    port: 8090,
    disableHostCheck: true,
    proxy: {
      "/gtd": {
        changeOrigin: true,
        target: "http://api.jituancaiyun.net",
      },
    },
  };
};

const path = require("path");

module.exports = {
  webpack: override(
    addWebpackModuleRule({
      test: /\.svg$/,
      use: [
        {
          loader: "@svgr/webpack",
          options: {
            babel: true,
          },
        },
      ],
    }),
    fixBabelImports("import", [
      {
        //配置按需加载
        libraryName: "antd",
        libraryDirectory: "es",
        style: true,
      },
      fixBabelImports("import", {
        libraryName: "@material-ui/core",
        libraryDirectory: "components", // default: lib
        camel2DashComponentName: false, // default: true
      }),
    ]),

    addWebpackAlias({
      //路径别名
      "@": path.resolve(__dirname, "src"),
    }),
    addLessLoader({
      javascriptEnabled: true,
      modifyVars: {
        "@primary-color": "#1DA57A",
      },
    }),
    (config) => {
      console.log("config", config);
      return config;
    }
  ),
  devServer: overrideDevServer(devServerConfig),
};
